<?php

/*
 * Formulaire d'identification
 */

class Application_Form_Authentification extends Zend_Form
{
	private $base_url;
	
	/* Surcharge du constructeur */
	public function __construct($options = null, $base_url){		
		$this->base_url = $base_url;

		parent::__construct($options);
	}
	
	public function init()
	{
		/* Form Elements & Other Definitions Here ... */
		$this->setName('authentification')
			 ->setAction($this->base_url.'/index') // ajouter Helper pour baseUrl plus helper de vue
			 ->setDisableLoadDefaultDecorators(true)
			 ->addDecorator('FormElements')
			 ->addDecorator('Form');
		
		$options = array(
			'title' => 'Identifiant',
			'name' => 'login'
		);
		$login = new Zend_Form_Element_Text($options);
		$login->setLabel('Login ')
			->setRequired(true)
			->addFilter('StripTags')
			->addFilter('StringTrim')
			->addValidator('Alnum')
			->addValidator('StringLength', false, array(1, 30))
			->setAttrib('class','input-block-level')
			->setAttrib('placeholder','Votre login...');
		
		$options = array(
			'title' => 'Mot de passe',
			'name' => 'password'
		);
		$password = new Zend_Form_Element_Password($options);
		$password->setLabel('Mot de passe ')
				->setRequired(true)
				->addFilter('StripTags')
				->addFilter('StringTrim')
				->addValidator('StringLength', false, array(1, 60))
				->setAttrib('class','input-block-level')
				->setAttrib('placeholder','Votre mot de passe...');
		
		$submit = new Zend_Form_Element_Submit('submit');
		$submit->setAttrib('id', 'submitbutton')
				->setAttrib('class', 'submit btn btn-large btn-primary')
				->setLabel('Valider');

		$this->addElements(array($login, $password, $submit));

	}
	
	public function render(Zend_View_Interface $view=null){
		$liste_elements = $this->getElements();
			
		$html = '<form class="form-signin" id="'.$this->getAttrib('id').'" action="'.$this->getAction().'" method="'.$this->getMethod().'">';
		$html .= '<h2 class="form-signin-heading">Connexion</h2>';
		$html .= $liste_elements['login']->renderViewHelper();
		$html .= $liste_elements['password']->renderViewHelper();
		$html .= $liste_elements['submit']->renderViewHelper();
		$html .= '</form>';
			
				
		   $this->_setIsRendered();
		   return $html;
	}
	
	
}
?>

